package com.sys.servlet.mgr.user;


import com.sys.entity.User;
import com.sys.pojo.JsonResult;
import com.sys.utils.WriteJson;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


@WebServlet("/mgr/user/showUserSession")
public class ShowUserSessionServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*
        有过滤器进行拦截，能走到该servlet，肯定是登录的用户
         */

        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");

        JsonResult jr = new JsonResult();
        jr.setCode(0);
        jr.setMsg("");
        jr.setData(user);

        WriteJson.write(resp,jr);

    }
}
